package ai4games_tests.tests;


import game2dai.World;
import game2dai.entities.Vehicle;
import game2dai.entityshapes.ps.ArrowPic;
import game2dai.entityshapes.ps.Hints;
import game2dai.maths.Vector2D;
import game2dai.steering.AutoPilot;
import processing.core.PApplet;

/**
 * Testing Interpose
 * @author Peter
 *
 */
public class GameTest_006 extends PApplet {


	World w;
	Vehicle a0, a1;
	Vector2D fixedPos;
	
	ArrowPic view;

	Vehicle p;
	AutoPilot sb0, sb1, sbp;

	long ct, et, lt;
	float deltaTime;


	public void setup(){
		size(600,600);
		w = new World(width, height);
		fixedPos = new Vector2D(width/2,  40);
		
		view = new ArrowPic(this);
		view.showHints(Hints.HINT_HEADING | Hints.HINT_VELOCITY);
		
		a0 = new Vehicle(new Vector2D(270, 0), // position
				20, // collision radius
				new Vector2D(20,0), // velocity
				50, // maximum speed
				new Vector2D(1,0), // heading
				1, // mass
				1, // turning rate
				200 // max force
				); 
		sb0 = new AutoPilot();
		sb0.seekOn(new Vector2D(width - 20, 300));
		a0.AP(sb0);
		a0.renderer(view);

		a1 = new Vehicle(new Vector2D(200, 400), // position
				20, // collision radius
				new Vector2D(20,0), // velocity
				50, // maximum speed
				new Vector2D(1,0), // heading
				1, // mass
				1, // turning rate
				200 // max force
				); 
		sb1 = new AutoPilot();
		sb1.seekOn(new Vector2D(width - 20, 300));
		a1.AP(sb1);
		a1.renderer(view);

		p = new Vehicle(new Vector2D(30, 300), // position
				20, // collision radius
				new Vector2D(20,20), // velocity
				100, // maximum speed
				new Vector2D(1,1), // heading
				1, // mass
				1, // turning rate
				200 // max force
				); 
		view = new ArrowPic(this);	
		view.showHints(Hints.HINT_HEADING | Hints.HINT_VELOCITY);
		sbp = new AutoPilot();
		sbp.interposeOn(a0, a1);
		sbp.interposeOn(a0, fixedPos);
		p.renderer(view);
		p.AP(sbp);

		w.add(a0);
		w.add(a1);
		w.add(p);
		
		ct = lt = millis();	
	}


	public void draw(){
		ct = millis();
		et = ct - lt;
		lt = ct;
		deltaTime = et / 3000.0f;

		background(220,255,220);

		w.update(deltaTime);
		w.draw();
		
		fill(255,0,0);
		noStroke();
		ellipse((float)fixedPos.x, (float)fixedPos.y, 6,6);
	}

}
